package com.ax.center.controller;

import com.ax.center.annotation.Logging;
import com.ax.center.dto.ApiResponse;
import com.ax.center.entity.Staff;
import com.ax.center.service.StaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author zy
 * @date 2023/7/4 15:08
 */

@RestController
@RequestMapping(value = "staffController")
@Api(tags = "工号服务")
@CrossOrigin(origins = "http://localhost:5173")
public class StaffController {
    @Autowired
    private StaffService staffService;

    @PostMapping("/无效的请求")
    public void test(@RequestBody Staff staff){
        return;
    }

    @GetMapping(value = "/insert")
    @ApiOperation(value = "工号新增接口")
    @Logging(description = "新增工号")
    public ApiResponse insert(){
        Staff insert = staffService.insert();
        return ApiResponse.ok(insert);
    }

    @GetMapping(value = "/update/{id}/{newId}")
    @ApiOperation(value = "工号修改接口")
    @Logging(description = "更新工号")
    public ApiResponse update(@PathVariable(value = "id")Long oldId,@PathVariable(value = "newId") String newId){
        return staffService.update(oldId,newId);
    }
    @GetMapping(value = "/updateStatus/{id}/{status}")
    @ApiOperation(value = "工号状态修改接口")
    @Logging(description = "更新工号状态")
    public ApiResponse updateStatus(@PathVariable(value = "id")Long id,@PathVariable(value = "status") String status){
       return staffService.updateStatus(id,status);
    }


    @GetMapping(value = "/delete/{id}")
    @ApiOperation(value = "工号删除")
    @Logging(description = "删除工号")
    public  ApiResponse delete(@PathVariable(value = "id")Long id){
        return staffService.deleteById(id);
    }

    @GetMapping(value = "/queryAll1")
    @ApiOperation(value = "查询完整工号")
    @Logging(description = "查询完整工号")
    public ApiResponse queryAll1(){
        return  staffService.queryAll1();
    }

    @GetMapping(value = "/queryAll2")
    @ApiOperation(value = "查询有效工号")
    @Logging(description = "查询有效工号")
    public ApiResponse queryAll2(){
        return  staffService.queryAll2();
    }

    @GetMapping(value = "/queryStaffWithUser")
    @ApiOperation(value = "查询工号")
    @Logging(description = "查询工号")
    public ApiResponse queryStaffWithUser(){
        return  staffService.queryStaffWithUser();
    }





}
